from tkinter import *

# 显式根窗口
root = Tk()

trees = (
    ('顶层窗口1', 'light blue'),
    ('顶层窗口2', 'light green'),
    ('顶层窗口3', 'red'),
)

for (tree, color) in trees:
    # 新建窗口
    win = Toplevel(root)
    # 标题
    win.title(tree)
    # 忽略关闭：很重要
    win.protocol('WM_DELETE_WINDOW', lambda: None)
    # 设置icon
    # win.iconbitmap('py-blue-trans-out.ico')
    # 关闭一个win
    msg = Button(win, text=tree, command=win.destroy)
    msg.pack(expand=YES, fill=BOTH)
    msg.config(padx=10, pady=10, bd=10, relief=RAISED)
    msg.config(bg='black', fg=color, font=('times', 30, 'bold italic'))

root.title('顶层窗口协议')
Label(root, text="主窗口", width=30).pack()
Button(root, text="关闭所有", command=root.quit).pack()
root.mainloop()
